package cn.training.controller;

import java.util.List;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HelloWorldService {
	
	
	@Autowired
	QueryDAO queryDao;
	@Autowired
	UpdateDAO updateDao;
	
    //1用户查询
	public UserBean searchUser(UserBean frm){
		UserBean result=queryDao.executeForObject("User.selectUser",frm, UserBean.class);
		return result;
	}
	
	//1插入用户
	public int insertUser(UserBean mm){
		
		return updateDao.execute("User.insertUser",mm);
	}
	
	
	//1通过id查询用户
	public UserBean searchname(UserBean nn){
		UserBean result=queryDao.executeForObject("User.selectname",nn, UserBean.class);
		return result;
	}
	
	//1更新用户
	public int updateUser(UserBean kk){
		return updateDao.execute("User.updateUser",kk);
	}
	
	//1查询所以用户
	public List<UserBean> selectall(UserBean ll){
		List<UserBean> result=queryDao.executeForObjectList("User.selectall", ll);
		return result;
	}
	
	//1删除用户
	public int deleteid(UserBean oo){
		return updateDao.execute("User.deleteid", oo);
	}
	
	
	//2查询用户
	public UserB searchyonghu(UserB aa){
		UserB userb=new UserB();
		userb.setUserid(aa.getUserid());
		userb.setPassword(aa.getPassword());
		UserB result=queryDao.executeForObject("User.select", userb, UserB.class);
		return result;
	}
	
	
	//2添加用户
	public int adduser(UserB bb){
		int result=0;
		try{
			result=updateDao.execute("User.add", bb);
		}catch(Exception e)
		{
		return 999;}
		return result;
	}
	
	//2查询所以用户
	public List<UserB> allyonghu(UserB ss){
		List<UserB> result=queryDao.executeForObjectList("User.allyonghu", ss);
		return result;
	}
	
	//2查询所以用户
	public List<UserB> yonghuid(UserB qq){
		List<UserB> result=queryDao.executeForObjectList("User.yonghuid", qq);
		return result;
	}
	
	//2删除用户
	public int deleteyonghu(UserB ss){
		return updateDao.execute("User.deleteyonghu", ss);
	}
	//2查询相应id下的用户
	public UserB selectid(UserB aa){
		UserB result=queryDao.executeForObject("User.selectid",aa, UserB.class);
		return result;
	}  

	//2更新用户
	public int updateYonghu(UserB uu){
		return updateDao.execute("User.updateYonghu",uu);
	}
	public UserB selectnameid(UserB ss){
		UserB result=queryDao.executeForObject("User.selectnameid",ss, UserB.class);
		return result;
	}	
}
